<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>

<style>

table label.error {
    margin-left: 5px;
    width: auto;
    display: inline;
    color: red;
}


</style>
<script>
$(document).ready(
					function() {
						$("#div1").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择负责人',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
							
								 if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
									  layer.alert("请选择一项", {icon: 6});
									 return false;
								  }
							 
								  var formSelect = document.getElementById("fromSelect");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 6});
								      return false;
								    }
							  
							  $("#xm").val($("#fromSelect").find("option:selected").text());
							  $("#directoryPrincipal").val($("#fromSelect").val());
							  $(this).dialog('close');
							}
						  }
						});
						
						/* $.ajax({
							  type: 'POST',
							  url: "${basePath}/directory/selectProject",
						      data:{projectId: $('#projectId').val()},
							  success:function(data){
								   if(data.msg=="100"){
									   $.each(data.list, function(i, item) {
											debugger;
										  $("#fromSelect").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
										  $("#sourseFromSelect2").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
										     
									  });
								   }else if(data.msg=="-100"){
									  
								   }
							  }
				      	});	 */

					});
	function showdiv() {
		$('#div1').dialog('open');
	}
</script>
</head>
<body>
     <form action="#" name="Form" id="Form" method="post">
        <input type="hidden" name="directoryId" id="directoryId"  value="${data.directoryId}"/>
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="80%">
			<tr>
				<td class="table-header" colspan="4">目录管理</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>项目名称：</td>
				<td class="table-contentTD" style="width: 70%">
				<select id ="projectId" name="projectId"  class ="selectList required">
					        <c:forEach items="${projectList}" var="data">
								 <option value="${data.id}">${data.projectName}</option>
						    </c:forEach>
				</select>
			</tr>
			<tr>
			<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>目录：</td>
				<td class="table-contentTD" style="width: 70%">
				<input type="text" id="directoryName" name="directoryName"  placeholder="目录"   value="${data.directoryName}"  class="required inputText" autocomplete="off"> 
			</tr>
			
		    <tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>负责人：</td>
				<td class="table-contentTD" style="width: 70%">
			    <input type="hidden" name="directoryPrincipal" id="directoryPrincipal"  value="${data.directoryPrincipal}"/>
				<input type="text" id="xm" name="xm"  readonly="readonly"  value="${data.xm}"  class="required  inputText"/>
				<input type="button" id="optionBtn" value="选择" class="inputButton"
					onclick="javascript:showdiv();" /></td>
			</tr>
		</table>
		<br />
		
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
				    <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="modify">	
			    <td><input type="button" id="btnSave" class="inputButton" style="text-align: center;" value="保存" /></td>
			    </kl:permission>
				<td><input type="button" id="Cancel" class="inputButton" style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton" value="返回" style="text-align: center;" /></td>
			</tr>
		</table>
		
		 <div id="div1" style="display: none;">
			<table cellpadding="0" cellspacing="0" border="0" class="table-border">
				  <tr>
				  	 <td style="clear:both; width: 70%">
				  	  <input class="text" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
				  	   <br/><label style="color:red;">未选中:</label><br/>
				  	   <select name="fromSelect" id="fromSelect" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
							ondblclick="moveField('fromSelect','toSelect');">
											<c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach> 
						</select>
							<select name="sourseFromSelect2" id="sourseFromSelect2"   multiple="false" style="width: 220px; height: 150px; display: none;" >
									     <c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach> 
  	    </select>
						
					 </td>
  	              </tr>
			</table>
		</div>
		
		<script>
		    $("#projectId").val("${data.projectId}");
			$(document).ready(function() {
				var _form=$("#Form").validate();
				$("#btnSave").click(function() {
					if(_form.form()){
						 validateObj();
					}
				});
				
				
				function validateObj(){
					 $.post('${basePath}/directory/validation',{directoryName:$("#directoryName").val(),projectId:$("#projectId").val(),directoryId:$("#directoryId").val()},function(data) {
			   			/*   var json = eval("(" + data + ")"); */
			   			 var json = typeof data=='string'?JSON.parse(data) :data;
						   if(json.msg=="-99"){
							   layer.alert('创建失败，服务器异常', {icon: 5});
				   			     return false;
						   }else if(json.msg!="0"){
							   layer.alert('目录名字已重复 请重新输入目录名称', {icon: 5});
				   			      return false;
						   }else{
							   document.Form.action ="${basePath}/directory/update";
							   document.Form.submit();
						   }   
			   		}); 
				}
				
				$("#Cancel").click(function() {
					  window.location.href ="${basePath}/directory/details?id="+ $("#directoryId").val();
		 		});
				
				
				$("#returnBut").click(function() {
		 			  window.location.href='${basePath}/directory/index';
		 		});
				
			});
		</script>
	</form>
</body>
</html>
